<h1 align="left">{$title} [<a href="manage_promotion_hotel.html">Quản lý khuyến mãi khách sạn</a>]</h1>

<div align="center">
{$message}
{$sucess_msg}
</div>
<table class="hotel-form" bordercolor="#CCCCCC" border="1" cellspacing="0" cellpadding="5"
       style="border-collapse:collapse;margin: 20px auto; min-width: 500px">
    <tr>
        <td colspan="2" align="right" style="font-size:24px">
            [ <a href="manage_promotion_hotel.html">Hủy</a> ]
        </td>
    </tr>
{if $hotel_promotion.id}
    <tr>
        <th align="right">ID:</th>
        <td>{$hotel_promotion.id}
            <input type="hidden" name="id" value="{$hotel_promotion.id}">
            <input type="hidden" name="hotel_id" value="{$hotel_promotion.hotel_id}">
            <input type="hidden" name="status" value="{$hotel_promotion.status}"></td>
    </tr>
    <tr>
        <th align="right">Khách sạn:</th>
        <td>
            {$hotel_promotion.hotel_name}
            {literal}
                <script type="text/javascript">
                    jQuery.post(WEB_DIR + "ajax.php?act=promotion&code=getPromotionByHotel", {
                                hotel_id:{/literal}{$hotel_promotion.hotel_id}{literal}
                            },
                            function (review) {
                                console.log(review);
                                if (review != "") {
                                    $("#list-promotion").html(review);
                                }else{
                                    $("#list-promotion").html("Không có khuyến mãi nào");
                                }

                            });
                    $('.loading').hide();
                </script>
            {/literal}
        </td>
    </tr>
    {else}
    <tr>
        <th align="right">Khách sạn:</th>
        <td><div id="edit-popup">
            <table class="tblpoint">
                <tr>
                    <th><label for="keyword_hotel">Tìm khách sạn:</label></th>
                    <td><input type="text" name="keyword" id="keyword_hotel"><input type="button" id="search_hotel" value="Tìm"><span id="notification"></span></td>
                </tr>
                <tr>
                    <th>Chọn khách sạn:</th>
                    <td id="choice_hotel"><label for="td_order"></label><span id="td_order" class="hotelselect"></span></td>
                </tr>
                <tr id="deal"></tr>
            {*<tr><th></th>
                <td><a href="javascript:void(0);" data-key="" id="ok">[ OK ]</a>
                    <a href="javascript:void(0);" id="close">[ Hủy ]</a></td>
            </tr>*}
            </table>
        </div>
            {literal}
                <script type="text/javascript">
                    /*Search khách sạn*/
                    $('#search_hotel').live('click',function () {
                        $('#deal').html('');
                        $('#deal2').html('');
                        $('#notification').val('');
                        var key = $('#keyword_hotel').val();
                        $.post(
                                'ajax.php?act=home&code=search_hotel_order',
                                {
                                    keyword:key
                                },
                                function (hotel) {
                                    if (hotel == 'not_login') {
                                        alert('Bạn chưa đăng nhập.');
                                    } else {
                                        if (hotel == 'no_result') {
                                            $('#notification').html('0 kết quả');
                                        } else {
                                            $('#td_order').html(hotel);
                                        }
                                    }
                                }
                        );
                        $('.chon_room').show();
                    });

                    /*Hiện deal khi chọn khách sạn*/
                    $('.hotelselect').click(function(){
                        var hotel = parseInt($('#order').val());
                        var type = 'room';
                        $.post(
                                'ajax.php?act=location&code=getItem',
                                {
                                    hotel:hotel,
                                    type:type
                                },
                                function (data) {
                                    $('#deal').html(data);
                                }
                        );
                    });
                </script>
            {/literal}
            {*{html_options name=hotel_id options=$hotel_cities selected=$hotel_promotion.hotel_id class=hotelselect}*}
            {literal}
                <script type="text/javascript">
                    $(document).ready(function () {
                        /*$(".hotelselect").change(function () {
                            $('.loading').show();
                            k = $(".hotelselect").val();
                            $(".allroom").hide();
                            $("#room_" + k).show();
                            $("#list-promotion").text("");
                            jQuery.post(WEB_DIR + "ajax.php?act=promotion&code=getPromotionByHotel", {
                                        hotel_id:k
                                    },
                                    function (review) {
                                        console.log(review);
                                        if (review != "") {
                                            $("#list-promotion").html(review);
                                        }else{
                                            $("#list-promotion").html("Không có khuyến mãi nào");
                                        }

                                    });
                            $('.loading').hide();
                        });*/
                    });
                </script>
            {/literal}
        </td>
    </tr>

{/if}
    {*<tr>
        <th align="right">Các khuyến mãi đang chạy:</th>
        <td>
            <span id="list-promotion"></span>
            <div class="loading" style="display: none;">
                <img src="style/images/loading.gif"/>
            </div>
        *}{*{if $running}
            {foreach from=$running item=i key=k}
                {$i.time_start} => {$i.time_end} giá {$i.price|price_format} (giảm {$i.percent}%) áp dụng
                cho {$i.name_room} <br>
            {/foreach}
        {/if}*}{*
        </td>
    </tr>*}
    <tr>
        <th align="right">Loại KM :</th>
        <td>
        {html_options name=type options=$type selected=$hotel_promotion.type}
            {*Áp dụng cho:
        {foreach from=$room item=i key=k name=foo}
            <select name="room_id_{$k}" id="room_{$k}" class="allroom"
                    {if $smarty.foreach.foo.first}{else}style="display: none;"{/if}>
                <option value="0">Toàn khách sạn</option>
                {foreach from=$i item=i2 key=k2}
                    <option value="{$i2.id}">Phòng {$i2.name}</option>
                {/foreach}
            </select>
        {/foreach}*}
        </td>
    </tr>
    <tr>
        <th align="right">Giá:</th>
        <td><input type="text" name="price" value="{$hotel_promotion.price}"></td>
    </tr>
    <tr>
        <th align="right">Phần trăm giảm giá:</th>
        <td><input type="text" name="percent" maxlength="2" value="{$hotel_promotion.percent}">%</td>
    </tr>
    <tr>
        <th align="right">Ngày bắt đầu:</th>
        <td><input type="text" name="time_start" id="time_start" class="time" value="{$hotel_promotion.time_start}">
        </td>
    </tr>
    <tr>
        <th align="right">Ngày kết thúc:</th>
        <td><input type="text" name="time_end" id="time_end" class="time" value="{$hotel_promotion.time_end}"></td>
    </tr>
    <tr>
        <td colspan="2" align="center">
            <input type="submit" value="Lưu thay đổi"/>
            <input type="reset" value="Reset form"/>
        </td>
    </tr>
</table>

{literal}
<script type="text/javascript">
    $(document).ready(function () {
        //DATE PICKER
        jQuery("#time_start").datepicker({
            dateFormat:"dd-mm-yy",
            changeMonth: false,
            firstDay:1,
            showButtonPanel:true,
            onSelect:function (selectedDate) {
                jQuery("#time_end").datepicker("option", "minDate", selectedDate);
            }
        });

        jQuery("#time_end").datepicker({
            dateFormat:"dd-mm-yy",
            changeMonth: false,
            firstDay:1,
            showButtonPanel:true
        });
    });
</script>
{/literal}
